package com.woke.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class CjPrice {
	private int id;
	private String cusprice;
	private String belongcj;
	private String sequence;
	
	public String getSequence() {
		return sequence;
	}
	public void setSequence(String sequence) {
		this.sequence = sequence;
	}
	public String getBelongcj() {
		return belongcj;
	}
	public void setBelongcj(String belongcj) {
		this.belongcj = belongcj;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	
	public String getCusprice() {
		return cusprice;
	}
	public void setCusprice(String cusprice) {
		this.cusprice = cusprice;
	}
	public CjPrice() {

	}
	
	public CjPrice(int id,String belongcj,String sequence,String cusprice) {
		super();
		this.id = id;
		this.belongcj=belongcj;
		this.sequence=sequence;
		this.cusprice = cusprice;
	}

	public static List<CjPrice> getData(String sql) {
		Connection con = null;
		Statement st = null;
		ResultSet rs = null;
		List<CjPrice> list = new ArrayList<CjPrice>();
		try {
			
			con = WokeConnection.getConnection();
			st = con.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				int id = rs.getInt("id");
				String belongcj = rs.getString("belongcj");
				String sequence=rs.getString("sequence");
				String cusprice = rs.getString("cusprice");
				CjPrice u = new CjPrice(id,belongcj,sequence, cusprice);
				list.add(u);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			WokeConnection.closeMySql(con, st, rs);
		}
		return list;
	}
	
	public int selectLendSize(){
		Connection conn = WokeConnection.getConnection();
		PreparedStatement pst=null;
		ResultSet rs=null;
		try {
			 pst = conn.prepareStatement("select count(*) from cjprice ");
			 rs = pst.executeQuery();
			if(rs.next()){
				int pagecount = rs.getInt(1);
				return pagecount;
			}
			return 0;
		} catch (Exception e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			return 0;

		}finally{
			WokeConnection.closeMySql(conn, pst, rs);
		}
	}
	
	public int selectLendSize1(String cjid){
		Connection conn = WokeConnection.getConnection();
		PreparedStatement pst=null;
		ResultSet rs=null;
		try {
			 pst = conn.prepareStatement("select count(*) from cjprice ");
			 rs = pst.executeQuery();
			if(rs.next()){
				int pagecount = rs.getInt(1);
				return pagecount;
			}
			return 0;
		} catch (Exception e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			return 0;

		}finally{
			WokeConnection.closeMySql(conn, pst, rs);
		}
	}
	
	public List<CjPrice> selectLend(int pageNow, int pageSize){

		List<CjPrice> list = new ArrayList<CjPrice>();
		Connection conn = WokeConnection.getConnection();
		PreparedStatement pst=null;
		ResultSet rs=null;
		
		try {
			int startIndex =0;
			int endIndex = pageSize;
			String sql = "select  * from cjprice ";
			String sw = " where " + " 1=1 " + " order by id Desc ";
			// sql +=" where " + strWhere ;
			if (pageNow > 1) {
				startIndex = pageSize * (pageNow - 1);
				// endIndex = pageSize * currentPage;
			}
			sql += sw + " limit " + startIndex + "," + endIndex;
			
			 pst= conn.prepareStatement(sql);
			 rs= pst.executeQuery();
			while(rs.next()){
				CjPrice s= new CjPrice();
				s.setId(rs.getInt(1));
				s.setBelongcj(rs.getString(2));
				s.setSequence(rs.getString(3));
				s.setCusprice(rs.getString(4));
				list.add(s);
			}
			return list;
		} catch (Exception e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			return null;

		}finally{

			WokeConnection.closeMySql(conn, pst, rs);

		}

	}
	
	public List<CjPrice> selectLend1(int pageNow, int pageSize,String id){

		List<CjPrice> list = new ArrayList<CjPrice>();
		Connection conn = WokeConnection.getConnection();
		PreparedStatement pst=null;
		ResultSet rs=null;
		
		try {
			int startIndex =0;
			int endIndex = pageSize;
			String sql = "select  * from cjprice ";
			String sw = " where " + " 1=1 " + " and id='"+id+"'order by id Desc ";
			// sql +=" where " + strWhere ;
			if (pageNow > 1) {
				startIndex = pageSize * (pageNow - 1);
				// endIndex = pageSize * currentPage;
			}
			sql += sw + " limit " + startIndex + "," + endIndex;
			
			 pst= conn.prepareStatement(sql);
			 rs= pst.executeQuery();
			while(rs.next()){
				CjPrice s= new CjPrice();
				s.setId(rs.getInt(1));
				s.setBelongcj(rs.getString(2));
				s.setSequence(rs.getString(3));
				s.setCusprice(rs.getString(4));
				list.add(s);
			}
			return list;
		} catch (Exception e) {

			// TODO Auto-generated catch block

			e.printStackTrace();

			return null;

		}finally{

			WokeConnection.closeMySql(conn, pst, rs);

		}

	}
	
	

	
}
